let cropper = new Cropper($('#image')[0], {
  aspectRatio: 1, // 裁剪图层的横纵比例
  preview: $('.img-preview'), // 多看文档里每个属性的意思, 一般都会有, 实在没用自己写/换个插件
})
$('.select').on('click', function () {
  console.log('---')
  $('#file').click()
})
$('#file').on('change', function (e) {
  console.log(e.target.files[0])
  const file = e.target.files[0]
  const str = URL.createObjectURL(file)
  cropper.replace(str)
  getPic()
})
$('.sure').on('click', async function () {
  let canvas = cropper.getCroppedCanvas({
    width: 100,
    height: 100,
  })
  let base64Str = canvas.toDataURL('image/jpeg')
  base64Str = encodeURIComponent(base64Str)
  const res = await PostUploadAvatar({ avatar: base64Str })
  console.log(res)
  window.parent.reqGetInfo()
})
async function getPic() {
  const res = await GetUserInfo()
  console.log(res)
  const userpic = res.data.data.user_pic
  console.log(userpic)
  if (userpic) {
    $('#image').attr('src', userpic)
  }
}
getPic()
